package cn.java79.springboot.zsb.service;

import cn.java79.springboot.zsb.dao.AdvitseMapper;
import cn.java79.springboot.zsb.entity.Advtise;
import cn.java79.springboot.zsb.entity.User;
import cn.java79.springboot.zsb.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
@CacheConfig(cacheNames = "advtise")
@Cacheable(keyGenerator = "keyg")
public class AdvitseServiceImpl extends ServiceImpl<AdvitseMapper, Advtise> implements AdvitseService {

    @Override
    public Page<Advtise> search(String title, String url, Date start, Date end, int pageNo, int pageSize) {
        QueryWrapper<Advtise> q = new QueryWrapper<>();
        q.like(!StrUtil.isBlank(title), "title", title);
        q.like(!StrUtil.isBlank(url), "url", url);
        q.ge(!StrUtil.isBlank(start), "starttime", start);
        q.le(!StrUtil.isBlank(end), "starttime", end);
        Page<Advtise> p = new Page<>(pageNo, pageSize);
        p = super.page(p, q);
        return p;
    }
}
